import {TableColumn, TableColumnAction, TableColumnLabels, TableColumnTime, TableColumnLongText, TableStatus} from "@/components/AppTable/TableType";

/**
 * 处理数据列属性,尼玛的ts又丑又硬
 * @param columns
 * @param slotsKeys
 */
export default function (columns: Array<TableColumn>, slotsKeys: Array<string> = []): Array<TableColumn> {
    let NewsColumns: Array<TableColumn> = [];
    for (let column of columns) {
        if ((column as TableColumnAction).type === 'action') {
            column.width = column.width ? column.width : 130;
            column.align = column.align ? column.align : 'center'
            if (typeof (column as TableColumnAction).update === "undefined") {
                (column as TableColumnAction).update = true
            }
            if (typeof (column as TableColumnAction).remove === "undefined") {
                (column as TableColumnAction).remove = true
            }
            if (!((column as TableColumnAction).update || (column as TableColumnAction).remove || slotsKeys.indexOf('action') > -1)) {
                continue;
            }
        } else if ((column as TableColumnTime).type === 'timestramp') {
            (column as TableColumnTime).format = (column as TableColumnTime).format ? (column as TableColumnTime).format : 'Y-m-d H:i:s';
        } else if ((column as TableColumnLabels).type === 'labels') {

        } else if ((column as TableColumnLongText).type === 'long-text') {
            column.showOverflowTooltip = false
        } else if ((column as TableStatus).type === 'status') {
            (column as TableStatus).inactiveText = (column as TableStatus).inactiveText ? (column as TableStatus).inactiveText : '关闭';
            (column as TableStatus).activeText = (column as TableStatus).activeText ? (column as TableStatus).activeText : '开启';
        }
        NewsColumns.push({...column})
    }
    return NewsColumns
}